package com.ds.kafka;

import lombok.extern.slf4j.Slf4j;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.util.Optional;

//@Component
@Slf4j
public class KafkaConsumer {

    @KafkaListener(topics = KafkaProducer.TOPIC_TEST,groupId = KafkaProducer.TOPIC_GROUP1)
	public void topic_test(ConsumerRecord<?, ?> record) {
        Optional message = Optional.ofNullable(record.value());
        System.out.println(message);
        if (message.isPresent()) {
            Object msg = message.get();
            log.info("topic_test 消费了,Message:" + msg);
        }
    }

    @KafkaListener(topics = KafkaProducer.TOPIC_TEST, groupId = KafkaProducer.TOPIC_GROUP1)
    public void topic_test1(ConsumerRecord<?, ?> record) {
        Optional message = Optional.ofNullable(record.value());
        if (message.isPresent()) {
            Object msg = message.get();
            log.info("topic_test1 消费了：,Message:" + msg);
        }
    }
    
//    @KafkaListener(topics = {KafkaProducer.TOPIC_TEST})
//    public void listen(ConsumerRecord<?, ?> record) {
//    	System.out.println("listen");
//        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
//        if (kafkaMessage.isPresent()) {
//            Object message = kafkaMessage.get();
//            log.info("----------------- record =" + record);
//            log.info("------------------ message =" + message);
//        }
//
//    }
}
